package org.infodavid.common.notifier.impl;

import org.infodavid.common.notifier.IAttachment;

/**
 * The Class AttachmentImpl.
 */
public class AttachmentImpl implements IAttachment {

  /** The Constant serialVersionUID. */
  private static final long serialVersionUID = 1242327795610967050L;

  /** The mime type. */
  private String mimeType = null;

  /** The name. */
  private String name = null;

  /** The description. */
  private String description = null;

  /** The data. */
  private byte[] data = null;

  /** The encoding. */
  private String encoding = DEFAULT_ENCODING;

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAttachment#getMimeType()
   */
  public String getMimeType() {
    return StringUtils.isNotEmpty(mimeType) ? DEFAULT_MIME_TYPE : mimeType;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAttachment#setMimeType(java.lang.String)
   */
  public void setMimeType(final String value) {
    mimeType = value;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAttachment#setData(byte[])
   */
  public void setData(final byte[] values) {
    data = values;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAttachment#getData()
   */
  public byte[] getData() {
    return data;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAttachment#setName(java.lang.String)
   */
  public void setName(final String value) {
    name = value;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAttachment#getName()
   */
  public String getName() {
    return name;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAttachment#getDescription()
   */
  public String getDescription() {
    return description;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAttachment#setDescription(java.lang.String)
   */
  public void setDescription(final String value) {
    description = value;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAttachment#getEncoding()
   */
  public String getEncoding() {
    return encoding == null || encoding.trim().length() == 0 ? DEFAULT_ENCODING : encoding;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAttachment#setEncoding(java.lang.String)
   */
  public void setEncoding(final String value) {
    encoding = value;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString() {
    final StringBuilder builder = new StringBuilder();

    builder.append(super.toString());
    builder.append(" [mimeType=");
    builder.append(mimeType);
    builder.append(", name=");
    builder.append(name);
    builder.append(", description=");
    builder.append(description);
    builder.append(", data=");

    if (data == null) {
      builder.append("null");
    }
    else {
      builder.append(data.length);
      builder.append(" bytes");
    }

    builder.append(", encoding=");
    builder.append(encoding);
    builder.append("]");

    return builder.toString();
  }
}
